<?php
require_once('./class/Partenaire.php');

switch(@$_GET['action']){

    default:
        echo _PARTENAIRE_;
    break;

    case "addForm":
        echo Partenaire::getAddForm();
        break;

    case "doAdd":
        $p = new Partenaire();
        $p->setNom($_POST['nom']);
        $p->addOrModify();
        echo $p->getNom()." ". _ADDED_;
        break;

    case "modifyForm":
        $p = Partenaire::getPartenaire($_GET['id']);
        echo $p->getModifyForm();
        break;

    case "doModify":
        $p = new Partenaire();
        $p->setId($_POST['id_partenaire']);
        $p->setNom($_POST['nom']);
        $p->addOrModify();
        echo _PARTENAIRE_.' '. _MODIFIED_;
        break;

    case "list":
        $array = Partenaire::getAllPartenaire();
        $html = '<table class="tablesorter">
						<thead>
							<th>'._ID_PARTENAIRE_.'</th>
							<th>'._NOM_PARTENAIRE_.'</th>
							<th>'._EDIT_.'</th>
							<th>'._DELETE_.'</th>
						</thead><tbody>';
        $i = 0;
        foreach($array as $r){
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
						<td>'.$r->getId().'</td>
						<td> ' .$r->getNom().'</td>
						<td><a href="?module=partenaire&action=modifyForm&id='.$r->getId().'">'._EDIT_.'</a></td>
						<td><a href="?module=partenaire&action=delete&id='.$r->getId().'">'._DELETE_.'</a></td>
					</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;

    case "delete":
        $p = Partenaire::getPartenaire($_GET['id']);
        $p->delete();
        echo $p->getNom().' '. _DELETED_;
        break;
}
?>
